var e = require("../../../@babel/runtime/helpers/slicedToArray");
require("../../../@babel/runtime/helpers/Objectentries");
var t = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  a = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../../utils/index"),
  i = require("../../../config/index"),
  s = n.helper.tabCommon,
  c = n.helper.location,
  l = n.tools.common,
  u = s.getmodeStorageKey(i.typeMode.recruit);
Component({
  externalClasses: ["custom-class"],
  useStore: function (e) {
    return {
      driverClasslist: e.global.driverClass,
      machineList: e.global.mechanicalClass,
      areaList: e.storage.areaTree
    }
  },
  properties: {
    type: {
      type: String,
      value: ""
    },
    value: {
      type: Array,
      value: []
    },
    isUpdateStorage: {
      type: Boolean,
      value: !0
    },
    max: {
      type: Number,
      value: 1
    }
  },
  data: {
    defaultActive: [0],
    selectNum: 0,
    hide: !1,
    totalNum: 0,
    list: []
  },
  methods: {
    onCancel: function (e) {
      var t = this;
      this.setData({
        hide: !0
      }), setTimeout((function () {
        t.setData({
          hide: !1
        }), t.triggerEvent("close")
      }), 200)
    },
    onSubmit: function () {
      var e = this;
      return r(t().mark((function r() {
        var n, i, c;
        return t().wrap((function (t) {
          for (;;) switch (t.prev = t.next) {
            case 0:
              if (n = e.getSelectItem(), e.onCancel(), i = {
                  value: n,
                  label: n.map((function (e) {
                    return e.name
                  })).join()
                }, !e.data.isUpdateStorage) {
                t.next = 7;
                break
              }
              return c = a(a({}, s.getFilterParamsInfo(u)), {}, {
                type: i
              }), t.next = 7, s.setFilterParamsInfo(u, c);
            case 7:
              e.triggerEvent("change", i);
            case 8:
            case "end":
              return t.stop()
          }
        }), r)
      })))()
    },
    getSelectItem: function () {
      var t = this,
        a = this.selectComponent("#selector").data.childActive,
        r = [];
      return Object.entries(a).forEach((function (a) {
        var n = e(a, 2),
          i = n[0];
        n[1].forEach((function (e) {
          r.push(t.data.list[i].children[e])
        }))
      })), r
    },
    childClick: function (e) {
      var t = e.detail,
        a = t.activeAry;
      void 0 !== t.parent ? this.setData({
        selectNum: a.length
      }) : this.setData({
        selectNum: 0
      });
      var r = this.getSelectItem().length;
      this.setData({
        totalNum: r
      })
    }
  },
  lifetimes: {
    attached: function () {
      var e = this;
      return r(t().mark((function a() {
        var r, n, i, s, l, u;
        return t().wrap((function (t) {
          for (;;) switch (t.prev = t.next) {
            case 0:
              r = e.data, n = r.machineList, i = r.driverClasslist, s = r.areaList, l = r.type, t.t0 = l, t.next = "area" === t.t0 ? 4 : "machine" === t.t0 ? 8 : 10;
              break;
            case 4:
              return t.next = 6, c.transAreaData(s, !1);
            case 6:
              return u = t.sent, t.abrupt("break", 11);
            case 8:
              return u = n, t.abrupt("break", 11);
            case 10:
              u = i;
            case 11:
              e.setData({
                list: u
              });
            case 12:
            case "end":
              return t.stop()
          }
        }), a)
      })))()
    },
    ready: function () {
      var e = this.data,
        t = e.value,
        a = e.isUpdateStorage,
        r = e.list,
        n = t || [];
      if (a) {
        var i = s.getFilterParamsInfo(u).type.value;
        i && (n = i)
      }
      if (n.length) {
        var c = {};
        n.forEach((function (e) {
          var t = l.getTreeById(r, e.id),
            a = r.findIndex((function (e) {
              return t.pid === e.id
            })),
            n = c[a] || [],
            i = r[a].children.findIndex((function (t) {
              return e.id == t.id
            }));
          n.push(i), c[a] = n
        }));
        var o = Object.keys(c).map((function (e) {
            return +e
          })),
          h = c;
        this.selectComponent("#selector").setDataValue({
          currentActive: o[0],
          activeAry: o,
          childActive: h
        });
        var d = this.getSelectItem().length;
        this.setData({
          selectNum: n.length,
          totalNum: d
        })
      }
    }
  }
});